package main

import (
	"fmt"
	"os"
	"bufio"
	"strings"
	"io"
)


func BuildConf(path string, dict map[string]map[string]interface{}){
	file,err := os.Open(path)
	if err != nil {
		panic("Cant Open file")
	}
	reader := bufio.NewReader(file)
	section := ""
	for {
		str,err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		if err != nil {
			panic("Read Content Panic")
		}
		str = strings.TrimSpace(str)
		if strings.HasPrefix(str,"#") {
			continue
		}
		if strings.HasPrefix(str,"[") && strings.HasSuffix(str, "]") {
			arr := strings.Split(str, "[]")
			str = strings.TrimSpace(arr[0])
			section = str
			dict[str] = make(map[string]interface{})			
		}
		arr := strings.Split(str, "=")
		key,value := arr[0], arr[1]
		key = strings.TrimSpace(key)
		value = strings.TrimSpace(value)
		if section == "" {
			dict["_global"][key] = value
		}else {
			dict[section][key] = value
		}
	}	


}

func Main() {
	c := make(chan bool)
	dict := map[string]map[string]interface{}{}

	BuildConf("temp.ini", dict)

	go func (){
		for {

		}

	}()
}
